package com.celesea.auth.role.service;

import com.celesea.auth.role.dao.RolePermissionDao;
import com.celesea.auth.role.entity.RolePermission;
import com.celesea.auth.role.entity.RoleUser;
import com.celesea.framework.service.AbstractBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class RolePermissionServiceImpl
        extends AbstractBaseService<RolePermission> implements RolePermissionService {

    @Autowired
    private RolePermissionDao dao;

    @Override
    public List<RolePermission> findByRole(String roleId) {
        return dao.selectByExample(buildExample(roleId));
    }

    @Override
    public int deleteByRole(String roleId) {
        return dao.deleteByExample(buildExample(roleId));
    }

    private Example buildExample(String roleId) {
        Example example = new Example(RoleUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("roleId", roleId);
        return example;
    }
}
